package com.example.michong.controller;

import com.example.michong.entity.PatternProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
/**
 * 配置热更新@RefreshScope
 */
@RefreshScope
@RestController
@RequestMapping("/nacos")
@Api("nacos的热更新记录")
public class NacosConfigApi {

    @Value("${pattern.dateformat}")
    private String dateformat;

    @ApiOperation("@value的热配置")
    @GetMapping("/now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateformat));
    }


    @Autowired
    private PatternProperties patternProperties;

    @ApiOperation("entity的热配置")
    @GetMapping("/now1")
    public String now1(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
    }
}